<?php
namespace Shop\Model;
use Think\Model;

class ShopRemarkModel extends Model{
	protected $tableName='shop_remark';
	protected $_validate = array(
		array('remark','0,255','回复内容不能超过255个字符',1,'length'),
		array('order_id','/[1-9]\d*/','order_id参数错误',Model::MUST_VALIDATE),
	);
	protected $_auto = array(
		array('create_time', NOW_TIME, 1),
	);

	public function add_or_edit_shop_remark($shop_remark)
	{
		if(!empty($shop_remark['id']))
		{
			$ret = $this->where('id = '.$shop_remark['id'])->save();
		}
		else
		{
			$ret = $this->add($shop_remark);
		}
		return $ret;
	}

	public function delete_shop_remark($ids)
	{
		is_array($ids) || $ids = array($ids);
		return $this->where('id in ('.implode(',',$ids).')')->delete();
	}

	public function get_shop_remark_list($option)
	{
		if(!empty($option['order_id'])) {
			$where_arr[] = 'order_id= '.$option['order_id'];
		}
		$where_arr[] = 'is_del= 0';

		$where_str = '';
		if (!empty($where_arr))
		{
			$where_str .=  implode(' and ', $where_arr);
		}
		$ret['list']  = $this->where($where_str)->page($option['page'], $option['r'])->select();
		$ret['count'] = $this->where($where_str)->count();
		return $ret;
	}

	public function get_shop_remark_by_id($id)
	{
		$ret = $this->where('id = '.$id)->find();
		return $ret;
	}



}

